Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 337)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.51073 11.55187 11.59253 11.63273 11.67248 11.71181 11.75073 11.78925
## [9] 11.82739 11.86516 11.90259 11.93968 11.97646 12.01292 12.04902 12.08475
## [17] 12.12007 12.15497 12.18943 12.22342 12.25692 12.28990 12.32262 12.35530
## [25] 12.38784 12.42016 12.45217 12.48379 12.51492 12.54549 12.57539 12.60456
## [33] 12.63289 12.66031 12.68787 12.71636 12.74534 12.77433 12.80289 12.83054
## [41] 12.85682 12.88127 12.90344 12.92509 12.94799 12.97165 12.99557 13.01928
## [49] 13.04229 13.06411 13.08425 13.10222 13.11754 13.12972 13.13828 13.14472
## [57] 13.15065 13.15575 13.15971 13.16221 13.16291 13.16151 13.15768 13.15111
## [65] 13.14043 13.12496 13.10542 13.08250 13.05690 13.02933 13.00049 12.97107
## [73] 12.94179 12.91334 12.88643 12.86175 12.83299 12.79562 12.75300 12.70852
## [81] 12.66553 12.62742 12.59755 12.57132 12.54247 12.51191 12.48053 12.44925
## [89] 12.41897 12.39058 12.36500 12.34314 12.32401 12.30601 12.28908 12.27317
## [97] 12.25820 12.24414 12.23092 12.21848 12.20676 12.19572 12.18528 12.17540
## [105] 12.16678 12.15998 12.15473 12.15073 12.14770 12.14535 12.14341 12.14158
## [113] 12.13958 12.13838 12.13893 12.14100 12.14432 12.14864 12.15370 12.15924
## [121] 12.16501 12.17075 12.17620 12.18112 12.18524 12.19010 12.19702 12.20543
## [129] 12.21471 12.22430 12.23360 12.24201 12.24896 12.25385 12.25733 12.26050
## [137] 12.26339 12.26608 12.26863 12.27109 12.27352 12.27598 12.27853 12.28123
## [145] 12.28414 12.28731 12.28923 12.28869 12.28623 12.28239 12.27772 12.27275
## [153] 12.26803 12.26410 12.26150 12.26077 12.26245 12.26709 12.27522 12.28738
## [161] 12.30268 12.31962 12.33779 12.35683 12.37633 12.39593 12.41522 12.43847
## [169] 12.46933 12.50652 12.54875 12.59473 12.64319 12.69284 12.74240 12.79057
## [177] 12.83609 12.87766 12.91399 12.94382 12.96584 12.98504 13.00677 13.03029
## [185] 13.05489 13.07982 13.10437 13.12781 13.14940 13.16843 13.18415 13.19585
## [193] 13.20280 13.20426 13.19952 13.18673 13.16568 13.13807 13.10559 13.06996
## [201] 13.03285 12.99598 12.96105 12.92974 12.89690 12.85704 12.81139 12.76120
## [209] 12.70769 12.65211 12.59569 12.53966 12.48527 12.43374 12.38632 12.34424
## [217] 12.30392 12.26144 12.21751 12.17285 12.12817 12.08418 12.04159 12.00111
## [225] 11.96346 11.92691 11.88954 11.85171 11.81379 11.77614 11.73913 11.70314
## [233] 11.66852 11.63566 11.60492 11.57666 11.55125 11.52643 11.50027 11.47371
## [241] 11.44765 11.42302 11.40072 11.38169 11.36683 11.35458 11.34301 11.33245
## [249] 11.32325 11.31574 11.31027 11.30718 11.30682 11.30981 11.31631 11.32592
## [257] 11.33822 11.35282 11.36931 11.38728 11.40634 11.42607 11.44608 11.46595
## [265] 11.48529 11.50947 11.54246 11.58178 11.62492 11.66939 11.71270 11.75236
## [273] 11.78586 11.81071 11.83091 11.85193 11.87351 11.89540 11.91734 11.93905
## [281] 11.96030 11.98081 12.00034 12.01861 12.03537 12.05036 12.06212 12.07006
## [289] 12.07521 12.07863 12.08134 12.08438 12.08881 12.09564 12.10594 12.11776
## [297] 12.12863 12.13876 12.14835 12.15763 12.16681 12.17609 12.18569 12.19582
## [305] 12.20669 12.21852 12.23152 12.24522 12.25904 12.27297 12.28705 12.30128
## [313] 12.31568 12.33027 12.34506 12.36006 12.37529 12.39077 12.40650 12.42251
## [321] 12.43882 12.45539 12.47220 12.48924 12.50651 12.52400 12.54172 12.55965
## [329] 12.57778 12.59612 12.61463 12.63327 12.65205 12.67099 12.69009 12.70937
## [337] 12.72885
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 337)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.73188 10.82231 10.91098 10.99785 11.08292 11.16617 11.24757 11.32712
## [9] 11.40479 11.48056 11.55441 11.62634 11.69632 11.76434 11.83045 11.89467
## [17] 11.95704 12.01757 12.07631 12.13329 12.18853 12.24206 12.29366 12.34313
## [25] 12.39054 12.43597 12.47950 12.52120 12.56115 12.59941 12.63607 12.67121
## [33] 12.70489 12.73719 12.76753 12.79541 12.82108 12.84475 12.86668 12.88709
## [41] 12.90621 12.92428 12.94154 12.95625 12.96690 12.97407 12.97833 12.98024
## [49] 12.98037 12.97929 12.97758 12.97580 12.97451 12.97430 12.97573 12.97711
## [57] 12.97664 12.97472 12.97173 12.96806 12.96411 12.96028 12.95694 12.95449
## [65] 12.95282 12.95142 12.95010 12.94867 12.94696 12.94476 12.94190 12.93818
## [73] 12.93343 12.92745 12.92005 12.91105 12.90045 12.88855 12.87564 12.86197
## [81] 12.84784 12.83352 12.81927 12.80486 12.78988 12.77440 12.75844 12.74206
## [89] 12.72529 12.70819 12.69080 12.67315 12.65511 12.63646 12.61718 12.59723
## [97] 12.57659 12.55522 12.53310 12.51018 12.48644 12.46185 12.43638 12.40999
## [105] 12.37781 12.33677 12.28956 12.23887 12.18738 12.13777 12.09273 12.05494
## [113] 12.02709 12.00398 11.97907 11.95309 11.92674 11.90074 11.87580 11.85262
## [121] 11.83193 11.81442 11.80081 11.79182 11.78815 11.78981 11.79578 11.80520
## [129] 11.81721 11.83096 11.84560 11.86027 11.87412 11.88630 11.90019 11.91920
## [137] 11.94248 11.96921 11.99854 12.02965 12.06169 12.09382 12.12522 12.15504
## [145] 12.18245 12.20661 12.23042 12.25704 12.28602 12.31694 12.34935 12.38281
## [153] 12.41688 12.45111 12.48508 12.51833 12.55044 12.58095 12.60943 12.63544
## [161] 12.65805 12.67733 12.69439 12.71032 12.72622 12.74318 12.76229 12.78404
## [169] 12.80789 12.83343 12.86026 12.88797 12.91614 12.94437 12.97225 12.99937
## [177] 13.02532 13.04970 13.07209 13.09209 13.10928 13.12611 13.14490 13.16511
## [185] 13.18619 13.20757 13.22872 13.24908 13.26809 13.28520 13.29987 13.31153
## [193] 13.31964 13.32365 13.32300 13.31830 13.31072 13.30058 13.28816 13.27377
## [201] 13.25771 13.24027 13.22176 13.20248 13.18104 13.15610 13.12810 13.09745
## [209] 13.06456 13.02984 12.99371 12.95660 12.91890 12.88104 12.84343 12.80649
## [217] 12.76601 12.71872 12.66647 12.61107 12.55438 12.49821 12.44441 12.39481
## [225] 12.35124 12.30982 12.26585 12.21993 12.17267 12.12465 12.07648 12.02876
## [233] 11.98209 11.93707 11.89429 11.85437 11.81789 11.78229 11.74522 11.70759
## [241] 11.67033 11.63435 11.60058 11.56993 11.54332 11.51959 11.49703 11.47576
## [249] 11.45592 11.43762 11.42097 11.40612 11.39317 11.38214 11.37293 11.36551
## [257] 11.35984 11.35588 11.35360 11.35295 11.35391 11.35644 11.36049 11.36604
## [265] 11.37304 11.38307 11.39712 11.41431 11.43373 11.45450 11.47573 11.49653
## [273] 11.51600 11.53324 11.55114 11.57271 11.59735 11.62443 11.65333 11.68342
## [281] 11.71408 11.74469 11.77462 11.80326 11.82997 11.85414 11.87763 11.90245
## [289] 11.92825 11.95465 11.98129 12.00781 12.03382 12.05898 12.08291 12.10609
## [297] 12.12924 12.15230 12.17523 12.19798 12.22051 12.24276 12.26469 12.28626
## [305] 12.30742 12.32811 12.34830 12.36807 12.38752 12.40667 12.42554 12.44414
## [313] 12.46249 12.48060 12.49847 12.51614 12.53360 12.55088 12.56799 12.58493
## [321] 12.60174 12.61839 12.63487 12.65117 12.66725 12.68313 12.69876 12.71416
## [329] 12.72928 12.74413 12.75868 12.77293 12.78689 12.80057 12.81398 12.82716
## [337] 12.84010
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 337)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.84433 10.90643 10.96746 11.02739 11.08619 11.14385 11.20033 11.25561
## [9] 11.30966 11.36245 11.41396 11.46416 11.51304 11.56063 11.60705 11.65230
## [17] 11.69640 11.73937 11.78122 11.82197 11.86163 11.90022 11.93737 11.97279
## [25] 12.00660 12.03895 12.06996 12.09977 12.12851 12.15631 12.18331 12.20963
## [33] 12.23542 12.26080 12.28502 12.30743 12.32833 12.34801 12.36677 12.38490
## [41] 12.40270 12.42046 12.43847 12.45730 12.47706 12.49739 12.51793 12.53832
## [49] 12.55820 12.57721 12.59499 12.61118 12.62541 12.63734 12.64660 12.65348
## [57] 12.65863 12.66224 12.66447 12.66549 12.66549 12.66462 12.66308 12.66102
## [65] 12.65801 12.65355 12.64777 12.64078 12.63268 12.62360 12.61364 12.60293
## [73] 12.59157 12.57968 12.56737 12.55476 12.53922 12.51909 12.49593 12.47130
## [81] 12.44674 12.42384 12.40412 12.38379 12.35886 12.33071 12.30069 12.27015
## [89] 12.24046 12.21297 12.18905 12.17004 12.15413 12.13862 12.12355 12.10896
## [97] 12.09488 12.08134 12.06839 12.05607 12.04439 12.03342 12.02317 12.01370
## [105] 12.00595 12.00048 11.99671 11.99405 11.99192 11.98974 11.98692 11.98289
## [113] 11.97705 11.97041 11.96430 11.95870 11.95357 11.94888 11.94459 11.94067
## [121] 11.93708 11.93380 11.93077 11.92798 11.92539 11.92434 11.92571 11.92878
## [129] 11.93282 11.93711 11.94092 11.94351 11.94418 11.94218 11.93641 11.92677
## [137] 11.91409 11.89917 11.88285 11.86592 11.84921 11.83354 11.81972 11.80857
## [145] 11.80090 11.79754 11.79620 11.79428 11.79209 11.78994 11.78813 11.78698
## [153] 11.78679 11.78786 11.79052 11.79506 11.80180 11.81104 11.82310 11.83827
## [161] 11.85746 11.88052 11.90627 11.93351 11.96103 11.98763 12.01212 12.03840
## [169] 12.07056 12.10766 12.14876 12.19294 12.23925 12.28677 12.33455 12.38167
## [177] 12.42719 12.47017 12.50968 12.54479 12.57456 12.60389 12.63762 12.67476
## [185] 12.71432 12.75530 12.79671 12.83755 12.87684 12.91357 12.94676 12.97540
## [193] 12.99851 13.01508 13.02413 13.02626 13.02327 13.01599 13.00524 12.99183
## [201] 12.97659 12.96033 12.94388 12.92806 12.90967 12.88555 12.85656 12.82355
## [209] 12.78740 12.74895 12.70908 12.66863 12.62847 12.58947 12.55247 12.51834
## [217] 12.48151 12.43720 12.38753 12.33458 12.28045 12.22724 12.17703 12.13193
## [225] 12.09403 12.05823 12.01869 11.97640 11.93236 11.88757 11.84301 11.79969
## [233] 11.75859 11.72071 11.68705 11.65860 11.63635 11.62132 11.61276 11.60900
## [241] 11.60838 11.60922 11.60987 11.60867 11.60393 11.60156 11.60698 11.61785
## [249] 11.63181 11.64652 11.65963 11.66879 11.67165 11.67135 11.67246 11.67475
## [257] 11.67799 11.68196 11.68644 11.69119 11.69599 11.70063 11.70486 11.70847
## [265] 11.71123 11.71095 11.70647 11.69914 11.69032 11.68134 11.67356 11.66832
## [273] 11.66698 11.67088 11.67824 11.68638 11.69523 11.70474 11.71488 11.72558
## [281] 11.73681 11.74850 11.76062 11.77311 11.78592 11.79901 11.81441 11.83351
## [289] 11.85532 11.87882 11.90302 11.92690 11.94947 11.96971 11.98662 12.00239
## [297] 12.01965 12.03808 12.05734 12.07713 12.09711 12.11695 12.13634 12.15495
## [305] 12.17246 12.18853 12.20286 12.21600 12.22873 12.24108 12.25305 12.26464
## [313] 12.27587 12.28675 12.29728 12.30748 12.31735 12.32691 12.33615 12.34510
## [321] 12.35376 12.36205 12.36992 12.37740 12.38453 12.39133 12.39785 12.40412
## [329] 12.41017 12.41604 12.42182 12.42755 12.43317 12.43864 12.44389 12.44887
## [337] 12.45353
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")